<template>
	<uni-table ref="tableData" border stripe emptyText="暂无更多数据">
		<uni-tr>
			<uni-th width="50rpx" align="center">序号</uni-th>
			<uni-th width="100rpx" align="center">文件名</uni-th>
			<uni-th width="100rpx" align="center">操作</uni-th>
		</uni-tr>
		<uni-tr v-for="tableData in tableData" :key="tableData.id">
			<uni-td>
				<view align="center">{{ tableData.id }}</view>
			</uni-td>
			<uni-td>
				<view align="center">{{ tableData.name }}</view>
			</uni-td>
			<uni-td>
				<view style="display: flex;align-items: center;">
					<button class="uni-button" size="mini" type="primary" @tap="PassId(tableData.id)">查看</button>
					<button class="uni-button" size="mini" type="warn" @tap="Delete(tableData.id)">删除</button>
				</view>
			</uni-td>
		</uni-tr>
	</uni-table>
</template>

<script>
	export default {
		data() {
			return {
				tableData: {},
			}
		},
		created() {
			this.get()
		},
		methods: {
			onPullDownRefresh() {
				let _this = this
				setTimeout(function() {
					uni.stopPullDownRefresh();
					_this.into()
					uni.showToast({
						title: "刷新完成",
						duration: 1000
					})
				}, 1000);
			},
			get() {
				this.request({
					url: '/file/page?pageNum=1&pageSize=999',
					method: 'GET'
				}).then(res => {
					this.tableData = res.data.records
				})
			},
			PassId(id) {
				// console.log(id);
				uni.navigateTo({
					url: '../video/video?id=' + id,
				})
			},
			Delete(id) {
				this.request({
					url: '/file/' + id,
					method: 'delete'
				}).then(res => {
					if (res.code === '200') {
						uni.showToast({
							title: '删除成功',
						})
						this.get()
					}
				})
			}
		}
	}
</script>
